﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Controls_Library
{
    /// <summary>
    /// Contains all styles for controls and serves as utility class for styles
    /// </summary>
    internal sealed class ControlStyles
    {
        /// <summary>
        /// Holds the style for a control
        /// </summary>
        private struct ControlStyle
        {
            public StyleEnum StyleEnum;
            public Color BackColor;
            public Color ForeColor;
            public Color BorderColor;
            public Color OnClickColor;
            public Color OnHoverColor;
        }

        private static List<ControlStyle> controlStyles;
        static ControlStyles()
        {
            // Adds various ControlStyles to a list of all ControlStyles
            controlStyles = new List<ControlStyle>();
            // Dark ControlStyle
            controlStyles.Add(new ControlStyle
            {
                StyleEnum = StyleEnum.Dark,
                BackColor = Color.FromArgb(45, 45, 48),
                ForeColor = Color.White,
                BorderColor = Color.FromArgb(53, 152, 254),
                OnClickColor = Color.FromArgb(53, 152, 254),
                OnHoverColor = Color.Gray
            });
            // TODO: Light ControlStyle
            controlStyles.Add(new ControlStyle
            {

            });
            // TODO: Blue ControlStyle
            controlStyles.Add(new ControlStyle
            {

            });
        }

        /// <summary>
        /// Updates the style of an IStylable control
        /// </summary>
        /// <param name="stylableControl">Control that is supposed to get styled</param>
        /// <param name="style">Style to style the control with</param>
        public static void UpdateStyle(IStylable stylableControl, StyleEnum style)
        {
            // Finds the right ControlStyle for the passed StyleEnum
            foreach (ControlStyle currentStyle in controlStyles)
            {
                if (currentStyle.StyleEnum == style)
                {
                    // Styles the control
                    var c = stylableControl as IStylable;
                    c.BackColor = currentStyle.BackColor;
                    c.ForeColor = currentStyle.ForeColor;
                    c.FlatAppearance.BorderColor = currentStyle.BorderColor;
                    c.FlatAppearance.MouseDownBackColor = currentStyle.OnClickColor;
                    c.FlatAppearance.MouseOverBackColor = currentStyle.OnHoverColor;
                    c.FlatStyle = FlatStyle.Flat;
                    // Breaks out of the loop because there should be no ControlStyles with duplicate StyleEnums
                    return;
                }
            }
        }

        private ControlStyles() { }
    }
}
